﻿Shader "Dan/UI/UI_OpenSurface01"
{
    Properties
    {
        _MainTex ("MainTex", 2D) = "white" {}
        _Color ("Color", Color) = (0.07843138,0.3921569,0.7843137,1)
        [HDR]_IconColor("Icon Color", Color) = (0.6,0.5,0.6,1)
        _Emission ("Emission", Float ) = 1
        _Open ("Open", Range(0, 1)) = 0
        _G_CanvasOpacity ("Canvas Opacity", Float ) = 0.5
        _Scanline_Density ("Scanline_Density", Float ) = 16
        _ScanlineSpeed ("ScanlineSpeed", Float ) = 1
        _ScanlineContrast ("ScanlineContrast", Range(0, 1)) = 0.5
        _ShinnyAmplitude ("ShinnyAmplitude", Range(0, 1)) = 0
        _B_IconShakeStrength ("B_ShakeStrength", Range(0, 1)) = 0
    }
    
    SubShader
    {

        Tags { "IgnoreProjector"="True"
            "Queue"="Transparent"
            "RenderType"="Transparent" }
        LOD 100    
        Blend SrcAlpha OneMinusSrcAlpha
        ZWrite Off 
 
        Pass
        {
            Blend SrcAlpha OneMinusSrcAlpha
            Cull Off
            ZWrite Off
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            
            #include "UnityCG.cginc"
            #include "../ShaderLibs/UIFX.cginc"
            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };
            
            struct v2f
            {
                float4 vertex : SV_POSITION;    
                float2 uv : TEXCOORD0;
                
            };

             float4 _Color;
             sampler2D _MainTex; 
             float4 _MainTex_ST;
             float _Open;
             float _Emission;
             float _G_CanvasOpacity;
             float _Scanline_Density;
             float _ScanlineSpeed;
             float _ScanlineContrast;
             float _ShinnyAmplitude;
             float _B_IconShakeStrength;
             float4 _IconColor;

            v2f vert ( appdata v )
            {
                
                v2f o;
                UNITY_INITIALIZE_OUTPUT(v2f ,o);
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;        
                return o;
            }
            
            
            
            

            

            fixed4 frag (v2f i ) : SV_Target
            {
                    
                float2 uv = i.uv ;
                uv=TRANSFORM_TEX(uv, _MainTex);
            
                float3 finalColor = _Color.rgb*_Emission;
                 
                float2 shakeUV;
                float shinny;
                float flick;
                ShakeShinnyUV01(uv,_B_IconShakeStrength,_ShinnyAmplitude, shakeUV,flick, shinny);

                float scanLine =ScanLine02(uv.y,_Scanline_Density,_ScanlineSpeed,_ScanlineContrast);
            
                float4 open =OpenCanvas(uv,_MainTex,_Open);
                


                float canvas = open.g;
                float border = open.r;              
                float  backgroundTex = tex2D(_MainTex,uv).a;
                float iconShake = tex2D(_MainTex,shakeUV).b;
                float3 iconColor = iconShake*_IconColor*canvas;
               
               
               
                float Initiate;
                InitiateGlitch(_Open,flick,Initiate);
                float finalfx =border+(scanLine *_G_CanvasOpacity+backgroundTex+iconShake)*canvas;
                float shakeAlpha = finalfx*shinny*Initiate;
                float3 surfaceCol = finalColor+iconColor;


                return fixed4(surfaceCol,shakeAlpha);
                
         
         
                


            

            



            }
            ENDCG
        }
    }
    
    
    
}
